def vova(c):   
    if c == 1: return False   
    test = True   
    x = c - 1   
    while x > 1:   
        if not c % x:   
            test = False               
            break   
        x -= 1       
    return test  
     
n = input() 
r = [] 
for i in range(len(n) + 1): 
    for x in range(i,len(n) + 1): 
        if i == x: 
            continue 
        c = int(n[i:x]) 
        if vova(c): 
            r += [c] 
print(max(r) if r else 0)
